package com.khstudio.filebrowser;

import android.app.Activity;
import android.app.FragmentManager;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;

import com.khstudio.filebrowser.duallist.KhDualListFragment;
import com.khstudio.filebrowser.duallist.KhDualListFragment.onKhDualListFragmentListener;
import com.khstudio.filebrowser.util.KhLog;

public class FileBrowserActivity extends Activity {
    KhDualListFragment mKhDualListFragment;
    SharedPreferences mPrefs;

//    mCurrentPath = prefs.getString("CurrentPath", Environment.getExternalStorageDirectory().getAbsolutePath());
//    mStoragePath = prefs.getString("RepositoryPath", Environment.getExternalStorageDirectory().getAbsolutePath()+"/KVideoCapture/");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        KhLog.i("onCreate");

        setContentView(R.layout.kh_activity_khduallist);

        mPrefs = getSharedPreferences("KhVideoCapture", MODE_PRIVATE);
        String path = mPrefs.getString("DualListPath", Environment.getExternalStorageDirectory().getPath());

        FragmentManager fm = getFragmentManager();
        mKhDualListFragment = (KhDualListFragment)fm.findFragmentById(R.id.kh_duallist_fragment);
        mKhDualListFragment.setPath(path);
        mKhDualListFragment.setonKhDualListFragmentListener(new onKhDualListFragmentListener() {

            @Override
            public void onFolderChange(String path) {
                KhLog.i("onFolderChange = %s", path);
                SharedPreferences.Editor editor = mPrefs.edit();
                editor.putString("DualListPath", path);
                editor.commit();
            }

            @Override
            public void onFileClick(String path) {
                KhLog.i("onFileClick = %s", path);
            }
        });
//        mKhDualListFragment = KhDualListFragment.newInstance(Environment.getExternalStorageDirectory().getPath());
//
//        FragmentTransaction ft = getFragmentManager().beginTransaction();
//        ft.add(R.layout.kh_activity_khduallist, mKhDualListFragment);
//        ft.commit();
//
//        mKhDualListFragment = KhDualListFragment.newInstance(1);
//
//        FragmentTransaction ft = getFragmentManager().beginTransaction();
//        ft.add(R.id.duallist, fileFragment);
//        ft.add(R.id.duallist, folderFragment);
//        ft.commit();
//
//        final ImageView b = (ImageView) findViewById(R.id.duallistbutton);
//        b.setOnClickListener(new OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                LinearLayout view = (LinearLayout) fileFragment.getView();
//                view.setDrawingCacheEnabled(true);
//                Bitmap scrreenshot = view.getDrawingCache().copy(Bitmap.Config.ARGB_8888,true);
//                log.d("Measure width = %d height = %d", view.getMeasuredWidth(), view.getMeasuredHeight());
//                view.setDrawingCacheEnabled(false);
//                view.setLayoutParams(new LinearLayout.LayoutParams(200, 200));
//                b.setImageBitmap(scrreenshot);
//                log.d("width = %d height = %d", scrreenshot.getWidth(), scrreenshot.getHeight());
//            }
//        });
//        View v = fileFragment.getView();
//        v.setLayoutParams(new LayoutParams(200, 200));*/
    }

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.main, menu);
//        return true;
//    }

    @Override
    public void onBackPressed() {
        mKhDualListFragment.back();
    }

}
